package com.lsj.core.response;

import com.lsj.core.constant.response.ResponseConstant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel(value = "返回前端通用实体类")
public class BasicResponse<T> {
    @ApiModelProperty(value = "状态码")
    private Integer code;
    @ApiModelProperty(value = "提示信息")
    private String msg;
    @ApiModelProperty(value = "数据内容")
    private T data;

    public BasicResponse(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public BasicResponse(int code) {
        this.code = code;
    }

    public BasicResponse(int code, T data) {
        this.code = code;
        this.data = data;
    }

    public BasicResponse(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static BasicResponse success(){
        return new BasicResponse(ResponseConstant.SUCCESS);
    }
    public static BasicResponse success(String msg){
        return new BasicResponse(ResponseConstant.SUCCESS,msg);
    }
    public static BasicResponse success(Object data){
        return new BasicResponse(ResponseConstant.SUCCESS,data);
    }
    public static BasicResponse success(String msg,Object data){
        return new BasicResponse(ResponseConstant.SUCCESS,msg,data);
    }
    public static BasicResponse fail(){
        return new BasicResponse(ResponseConstant.FAIL);
    }
    public static BasicResponse fail(String msg){
        return new BasicResponse(ResponseConstant.FAIL,msg);
    }
    public static BasicResponse fail(Object data){
        return new BasicResponse(ResponseConstant.FAIL,data);
    }
    public static BasicResponse fail(String msg,Object data){
        return new BasicResponse(ResponseConstant.FAIL,msg,data);
    }

    public static  BasicResponse error(Integer code,String msg){
        return new BasicResponse(code,msg);
    }
}
